import { FormInstance } from 'antd';
import React from 'react';
import { Dispatch } from 'react';

interface UpdateAddOrEdit {
  addContractRun: (resObj: Record<string, any>) => void;
  editContractRun: (resObj: Record<string, any>) => void;
  editRecordContractRun: (resObj: Record<string, any>) => void;
  submitRecordContractRun: (resObj: Record<string, any>) => void;
  addContractAttachRun: (resObj: Record<string, any>) => void;
  addAndSubmitContractRun: (resObj: Record<string, any>) => void;
}

/** 合同管理页面上下文类型 */
export interface IContractContextAPI {
  styleFixCls: string;
  curRes: Record<string, any>;
  locationID: string;
  contractDispatch: Dispatch<any>;
  pageType: string;
  counterpartRows: Record<string, any>[];
  contractTempRow: Record<string, any>;
  contractForm: FormInstance | any;
  oldContractForm: FormInstance | any;
  contractDetailInfo: Record<string, any>;
  contarctJsonList: Record<string, any>;
  reloadDetail: () => void;
  updteAddOrEdit: UpdateAddOrEdit;
  oldContractInfo: Record<string, any>;
  locationState: Record<string, any>;
  getDetailInfoRun: (resObj: Record<string, any>) => void;
  materialCheckRows: Record<string, any>[];
  partyFirstSelectRows: Record<string, any>[];
  readReadShowFileRun: (resObj: Record<string, any>) => void;
  setOAMessageRun: (res: Record<string, any>) => any;
  taskId: string;
  locationProps: Record<string, any>;
}

/** 合同管理上下文 */
const INIT_CONTRACTCONTEXT_VALUE: IContractContextAPI = {
  styleFixCls: '',
  curRes: {},
  locationID: '',
  contractDispatch: () => {},
  pageType: '',
  counterpartRows: [],
  contractTempRow: {},
  contractForm: {},
  oldContractForm: {},
  contractDetailInfo: {},
  contarctJsonList: {},
  reloadDetail: () => {},
  updteAddOrEdit: {
    addContractRun: () => {},
    editContractRun: () => {},
    editRecordContractRun: () => {},
    submitRecordContractRun: () => {},
    addContractAttachRun: () => {},
    addAndSubmitContractRun: () => {},
  },
  oldContractInfo: {},
  locationState: {},
  getDetailInfoRun: () => {},
  materialCheckRows: [],
  partyFirstSelectRows: [],
  readReadShowFileRun: () => {},
  setOAMessageRun: () => {},
  taskId: '',
  locationProps: {},
};

const ConractControllerContext = React.createContext<IContractContextAPI>(INIT_CONTRACTCONTEXT_VALUE);

export { ConractControllerContext };
